package ui;

import com.gzbit.calculator.funsabstract.bll.AddOperation;
import com.gzbit.calculator.funsabstract.bll.MulOperation;
import com.gzbit.calculator.funsabstract.bll.Operation;
import com.gzbit.calculator.funsabstract.bll.SubOperation;

import java.util.Scanner;

//纯粹的界面逻辑代码
public class View {
    private int numberA, numberB;
    private String operator;
    //完成具体的业务逻辑：计算
    private Operation operation;

    public View(int numberA, int numberB, String operator) {
        this.numberA = numberA;
        this.numberB = numberB;
        this.operator = operator;
        this.NewOperation(operator);
    }

    /*
    * 根据运算符号确定实例化哪个运算类对象(“生产运算类对象”)
    * */
    public void NewOperation(String operator) {
        switch (operator) {
            case "+":
                operation = new AddOperation();
                break;
            case "-":
                operation = new SubOperation();
                break;
            case "*":
                operation = new MulOperation();
                break;
            default:
                operation = null;
        }
    }

    public View() {
        this.NewOperation(operator);
    }

    public void setValue(int numberA, int numberB, String operator) {
        this.numberA = numberA;
        this.numberB = numberB;
        this.operator = operator;
    }

    public int getResult() throws Exception {
        int result = operation.getResult();
        return result;
    }

    public void inputData() {
        Scanner scanner = new Scanner(System.in);
        this.numberA = scanner.nextInt();
        this.numberB = scanner.nextInt();
        this.operator = scanner.next();
    }

    public void outputResult() throws Exception {
        System.out.println(this.getResult());
    }
}
